// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },

  onPullDownRefresh:function(){
    this.onRefresh();
    // const res=await wx.request({
    //   url: xxx,
    //   method:xxx,
    //   data: xxx
    // })
  },

  onRefresh:function(){
      //导航条加载动画
      wx.showNavigationBarLoading();
      setTimeout(function () {
        wx.hideNavigationBarLoading();
        //停止下拉刷新
        wx.stopPullDownRefresh();
      }, 1000);
  },

  /**
   * 函数节流,防止误触或误以为网络不好导致请求多次发送到后台
   * @param {需要节流的代码段} fn 
   * @param {节流时间,毫秒} gapTime 
   */
  throttle:function(fn, gapTime) {
    if (gapTime == null || gapTime == undefined) {
        gapTime = 1500
    }
    let _lastTime = null
    // 返回新的函数
    return function () {
        let _nowTime = + new Date()
        if (_nowTime - _lastTime > gapTime || !_lastTime) {
            fn.apply(this, arguments)   //将this和参数传给原函数
            _lastTime = _nowTime
        }
    }
  },

  globalData: {
    userInfo: null,
    serverUrl:'https://centos.dusin.top:8443/WorkListServer/',
    // serverUrl:'http://localhost:8084/WorkListServer/',
    //serverUrl2:"https://centos.dusin.top:8443/WorkListServer2/"
    serverUrl2:'https://localhost:8088/WorkList2/',
  }
})
